{% extends 'admin/public/base.html' %}


{% block con-header %}
<div class="container-fluid am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
            <div class="page-header-heading">
                <span class="am-icon-home page-header-heading-icon"></span>
                商品列表
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block con-footer %}
<div class="row-content am-cf">


	<div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
	    <div class="am-form-group">
	        <div class="am-btn-toolbar">

	        </div>
	    </div>
	</div>
	<!-- 搜索表单 -->
	<form  >
		<!-- 搜索条件 -->
	    <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
	        <div class="am-form-group tpl-table-list-select">
	            <select name="types" data-am-selected="{btnSize: 'sm'}">
	                  <option {% if request.GET.types == 'all' %} selected {% endif %} value="all" >所有类别</option>
	                  <option {% if request.GET.types == 'id' %} selected {% endif %} value="id" >ID</option>
	                  <option {% if request.GET.types == 'title' %} selected {% endif %} value="title">商品标题</option>
	                  <option {% if request.GET.types == 'typeid' %} selected {% endif %} value="typeid">所属分类</option>
	                  <option {% if request.GET.types == 'price' %} selected {% endif %} value="price">价格</option>
	                  <option {% if request.GET.types == 'storage' %} selected {% endif %} value="storage">库存</option>
	                  <option {% if request.GET.types == 'num' %} selected {% endif %} value="num">购买数</option>
	                  <option {% if request.GET.types == 'clicknum' %} selected {% endif %} value="clicknum">点击数</option>
	                  <option {% if request.GET.types == 'addtime' %} selected {% endif %} value="addtime">添加时间</option>
	                  <option {% if request.GET.types == 'status' %} selected {% endif %} value="status">状态</option>
	            </select>
	        </div>
	    </div>
	    <!-- 搜索框 -->
	    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
	        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
	            <input name="keywords" type="text" class="am-form-field " value="{{ request.GET.keywords }}">
	            <span class="am-input-group-btn">
					<button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" >
					</button>
				</span>
	        </div>
	    </div>
	</form>

	<!-- 图文列表 -->
	<div class="am-u-sm-12">
	    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
	        <thead>
	            <tr>
	            	<th>缩略图</th>
					<th>ID</th>
	                <th>商品标题</th>
	                <th>所属分类</th>
	                <th>价格</th>
	                <th>库存</th>
	                <th>购买数</th>
	                <th>点击数</th>
	                <th>状态</th>
	                <th>添加时间</th>
	                <th>操作</th>
	            </tr>
	        </thead>
	        <tbody>
	        	{% for v in glist %}
	            <tr class="gradeX">
	                <td>
	                    <img src="{{ v.pic }}" class="tpl-table-line-img" alt="" width=50>
	                </td>
	                <td class="am-text-middle">{{ v.id }}</td>
	                <td class="am-text-middle">{{ v.title }}</td>
	                <td class="am-text-middle">
	                	{% load pagetag %}
		        		{%  duobiao  v.typeid.id %}
	            	</td>
	                <td class="am-text-middle">{{ v.price }}</td>
	                <td class="am-text-middle">{{ v.storage }}</td>
	                <td class="am-text-middle">{{ v.num }}</td>
	                <td class="am-text-middle">{{ v.clicknum }}</td>
	               	<td class="am-text-middle">
	                	<select gid="{{ v.id }}" class="user_status_save gid" style="color:black">
	                		{% if v.status == 1 %}
		                	<option value="1" selected>新品</option>
		                	<option value="2" >热销</option>
		                	<option value="3" >下架</option>
		                	{% elif v.status == 2 %}
		                	<option value="1" >新品</option>
		                	<option value="2" selected>热销</option>
		                	<option value="3" >下架</option>
		                	{% elif v.status == 3 %}
		                	<option value="1" >新品</option>
		                	<option value="2" >热销</option>
		                	<option value="3" selected>下架</option>
		                	{% endif %}
		                </select>
	            	</td>
	                <td class="am-text-middle">{{ v.addtime|date:'Y-m-d H:i:s' }}</td>
	                <td class="am-text-middle">
	                    <div class="tpl-table-black-operation">
	                        <a href="{% url 'admin_goods_edit' v.id %}">
	                            <i class="am-icon-pencil"></i> 编辑
	                        </a>
	                        <a href="" class="tpl-table-black-operation-del">
	                            <i class="am-icon-trash"></i> 删除
	                        </a>
	                    </div>
	                </td>
	            </tr>
	            {% endfor %}


	            <!-- more data -->
	        </tbody>
	    </table>
	</div>

	<!-- 分页 -->
	<div class="am-u-lg-12 am-cf">
		<div class="am-fr">
		    <ul class="am-pagination tpl-pagination">

		        {% load pagetag %}
		        {%  showPage  glist.paginator.num_pages request %}
		    </ul>
		</div>
	</div>


</div>
<script type="text/javascript">
	$('.user_status_save').change(function(){
		// 获取当前的选择状态
		res = $(this).val()
		// 获取用户id
		gid = $(this).attr('gid') 
		// 发送ajax请求修改用户状态
		$.get('{% url "admin_goods_status" %}',{gid:gid,status:res});

	});

	// ajax删除商品数据
	$('.tpl-table-black-operation-del').click(function(){
		a = $(this)
		// 获取要删除的商品数据的id
		gid = $(this).parents('.gradeX').find('.gid').attr('gid')
		// 发送ajax
		$.get('{% url "admin_goods_del" %}',{gid:gid},function(data){
			if (data['status'] == 3){
				a.parents('tr').remove()
			}
			alert(data['msg'])
		},'json');
		

		// 阻止默认行为
		return false;
	});
</script>
{% endblock %}